/**
 * @author liangxi
 * @since 2024/3/21
 */

#include <string>
#include <fstream>
#include <filesystem>
#include "../../../../Header/Behavior/Write/Impl/WriteToFile.h"

namespace fs = std::filesystem;

void WriteToFile::write(std::string_view msg, std::string_view fileName, std::string_view filePath) {
    std::string tmpName{fileName};
    std::string tmpPath{filePath};

    fs::path dirPath(tmpPath);

    //如果文件夹不存在 创建文件夹
    if (!fs::exists(dirPath)) {
        fs::create_directory(dirPath);
    }

    std::ofstream file(tmpPath + tmpName, std::ios::app);
    if (file.is_open()) {
        file << msg << std::endl;
        file.close();
    }
}
